#自动取款机
import os
#定义一个用于存放用户银行账号信息的列表变量
account=[{'numbers':'1234567890','password':'567890','balance':999999,'name':'zhangsan'},
         {'numbers':'0987654321','password':'765432','balance':888888,'name':'lisi'},
         {'numbers':'1122334455','password':'223344','balance':666666,'name':'wangwu'}]

#定义一个验证账号密码的函数
def check(acc,pin):
	for i in range(len(account)):
		if acc == account[i]["numbers"] and pin == account[i]["password"]:
			return i


#定义一个登录成功后用户操作页面
def services():
	print("="*12,"用户操作页面","="*12)
	print("{0:2}{1:12}{2:12}".format(" ","1.查询余额","2.取款"))
	print("{0:2}{1:12}{2:12}".format(" ","3.存款","4.退出界面"))
	print("="*40)


#定义一个查询余额的函数
def info(user_info):
	print("="*12,"账号查询页面","="*12)
	print("{0:<4} {1:<11} {2:<9}".format("账户名","卡号","余额"))
	print("{0:<5} {1:>11} {2:>9}".format(account[user_info]["name"],account[user_info]["numbers"],account[user_info]["balance"]))

#定义一个取款的函数
def withdraw(amount):

	i = account[user_info]["balance"] - int(amount)
	if i >= 0:
		account[user_info]["balance"] -= int(amount)
	else:
		print("余额不足\n")




#定义一个存款的函数
def deposit(amount):
	account[user_info]["balance"] += int(amount)
	print("存款成功，存款后余额为：",account[user_info]["balance"])
  
chance=3
while True:
		#输出初始界面
		print("="*12,"自动存取款系统","="*12)
		print("{0:1} {1:13} {2:15}".format("","1.登陆","2.退出"))
		print("="*40)
		key=input("请输入对应的选择：")
		#根据键盘值判断并执行对应的操作
		if key == "1":
			user_name=input("请输入银行账号：")
			print("")
			user_password=input("请输入银行密码：")
			print("")
			user_info=check(user_name,user_password)
			if user_info != None:
				print("登录成功！")

				while True:
					services()
					select=input("请选择操作选项:")
					if select == "1":
						info(user_info)
						input("按任意键返回：")
						print("")
					elif select=="2":
						print("="*12,"用户取款界面","="*12,"\n")
						amount=input("请输入取款金额：")
						withdraw(amount)
						info(user_info)
						input("按任意键返回：")
						print("")
					elif select=="3":
						print("="*12,"用户存款界面","="*12)
						amount = input("请输入存款金额：")
						deposit(amount)
						input("按任意键返回：")
						print("")
					elif select=="4":
						break
					else :
						print("输入无效,请重新输入。")
						print("")

			elif chance>1:
			    print("账户或密码错误，您还有",chance-1,"次机会")
			    chance-=1
			else:
			 	print("对不起，您输入账号密码错误次数已达3次，请联系客服")
			 	break
	
		elif key =="2":
			print("="*12,"谢谢使用，再见！","="*12)
			break


		else:
			print("="*12,"无效输入，请重新输入","="*12)
